package leetcode;

import java.util.*;

public class LeetCodeMain98 {

    public String PrintMinNumber(int [] numbers) {
        String str="";
        if (numbers==null||numbers.length==0){
            return str;
        }
        int length=numbers.length;
        String[] arr=new String[length];
        for (int i = 0; i < length; i++) {
            arr[i]=String.valueOf(numbers[i]);
        }
        Arrays.sort(arr,(o1, o2) ->(o1+o2).compareTo(o2+o1));
        for (String num:arr) {
            str+=num;
        }
        return str;
    }

    public static void main1(String[] args) {
        Scanner in=new Scanner(System.in);
        while (in.hasNext()){
            int num=in.nextInt();
            for (int i = 0; i < num; i++) {
                String str=in.next();
                System.out.println(func(str));
            }
        }
    }
    public static int func(String str) {
        int res=-1;
        int length=str.length();
        for (int i = 0; i < length/2; i++) {
            int j=length-1-i;
            char ch1=str.charAt(i);
            char ch2=str.charAt(j);
            if (ch1!=ch2){
                if (str.charAt(i+1)==str.charAt(j)){
                    res=i;
                }else if (str.charAt(i)==str.charAt(j-1)){
                    res=j;
                }
                break;
            }
        }
        return res;
    }
}
